Skip to content

Support using GlobalObjectStore for non-field-injected contexts - #12381

Open
mcculls wants to merge 3 commits into
masterfrom
mcculls/global-object-store-feature
Open

Support using GlobalObjectStore for non-field-injected contexts#12381
mcculls wants to merge 3 commits into
masterfrom
mcculls/global-object-store-feature

Conversation

@mcculls

@mcculls mcculls commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Adds a feature-flag to support switching non-field-injected InstrumentationContext from using a WeakMap per-store to instead use the shared GlobalObjectStore from dd-instrument-java.

The default value of this feature-flag is true, in other words the historical behaviour of using a map-per-store:

To switch to GlobalObjectStore set the following environment variable:

DD_TRACE_RUNTIME_CONTEXT_MAP_PER_STORE=false

or add this JVM option:

-Ddd.trace.runtime.context.map-per-store=false

Motivation

The GlobalObjectStore approach scales better for deployments using a lot of non-field-injected instrumentation context where periodic cleanup / GC cannot keep up. For example on AOT where we cannot field-inject classes linked at training time. See #10479 for more details.

GlobalObjectStore uses a generational approach to evict old content, keeping the store bounded while still allowing tracking of recent instrumentation contexts. Whereas the map-per-store approach immediately drops new content if the store reaches capacity, and this causes async propagation issues on AOT until GC finally kicks in.

Since the generational strategy is relatively new, the idea is to roll this out incrementally as we complete further benchmarking of various real-world applications.

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@mcculls mcculls added type: feature Enhancements and improvements tag: do not merge Do not merge changes comp: core Tracer core labels Sep 2, 2026
@datadog-official

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.79 s 14.66 s [-0.1%; +1.9%] (no difference)
startup:insecure-bank:tracing:Agent 13.59 s 13.68 s [-1.4%; -0.0%] (maybe better)
startup:petclinic:appsec:Agent 17.51 s 16.72 s [+0.5%; +9.0%] (maybe worse)
startup:petclinic:iast:Agent 17.25 s 17.52 s [-2.4%; -0.7%] (maybe better)
startup:petclinic:profiling:Agent 17.40 s 17.13 s [+0.1%; +3.1%] (maybe worse)
startup:petclinic:sca:Agent 17.06 s 17.43 s [-6.4%; +2.2%] (no difference)
startup:petclinic:tracing:Agent 16.53 s 16.22 s [-2.5%; +6.3%] (no difference)

Commit: edd9ecf2 · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@mcculls
mcculls force-pushed the mcculls/global-object-store-feature branch 5 times, most recently from 286fa56 to c7a0fb4 Compare September 3, 2026 11:47
@mcculls
mcculls force-pushed the mcculls/global-object-store-feature branch from de73d43 to ec23bdd Compare September 3, 2026 15:13
@mcculls mcculls changed the title WIP: Support using GlobalObjectStore for non-field-injected contexts Support using GlobalObjectStore for non-field-injected contexts Sep 3, 2026
@mcculls mcculls removed the tag: do not merge Do not merge changes label Sep 3, 2026
@mcculls
mcculls requested a lite review from Copilot September 3, 2026 15:50
@mcculls

mcculls commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@DataDog review

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

It modifies core runtime context storage and bytecode-injected fallback behavior, so it warrants a final human review to validate bootstrap/classloader safety and rollout risk.

Pull request overview

This PR adds a new configuration flag to control how non-field-injected InstrumentationContext storage behaves, allowing a rollout from the historical “weak map per store” fallback to the bounded, shared GlobalObjectStore implementation (from dd-instrument-java) for better scalability in scenarios like AOT class linking.

Changes:

  • Introduces trace.runtime.context.map-per-store (env: DD_TRACE_RUNTIME_CONTEXT_MAP_PER_STORE, default true) and wires it into InstrumenterConfig.
  • Switches non-field-injected context storage in FieldBackedContextStore (and injected accessor fallbacks) between WeakMapPerStore and GlobalObjectStore based on the new flag.
  • Refactors ContextStore factory APIs to use java.util.function.Function rather than a custom KeyAwareFactory.
File summaries
File Description
metadata/supported-configurations.json Registers the new env var flag in supported configuration metadata.
internal-api/src/main/java/datadog/trace/bootstrap/ContextStore.java Replaces custom key-aware factory type with Function and adapts Factory accordingly.
internal-api/src/main/java/datadog/trace/api/InstrumenterConfig.java Loads and exposes the new runtimeContextMapPerStore flag.
dd-trace-api/src/main/java/datadog/trace/api/ConfigDefaults.java Adds the default value constant for the new flag.
dd-trace-api/src/main/java/datadog/trace/api/config/TraceInstrumentationConfig.java Defines the canonical config key trace.runtime.context.map-per-store.
dd-java-agent/instrumentation/reactive-streams-1.0/src/test/java/datadog/trace/instrumentation/reactivestreams/ReactiveStreamsContextPropagationTest.java Updates a test ContextStore implementation to the new Function-based API.
dd-java-agent/instrumentation/graal/graal-native-image-20.0/src/main/java/datadog/trace/instrumentation/graal/nativeimage/NativeImageGeneratorRunnerInstrumentation.java Adds GlobalObjectStore classes to Graal native-image init-at-build-time list.
dd-java-agent/agent-tooling/src/main/java/datadog/trace/agent/tooling/context/FieldBackedContextInjector.java Selects the injected fallback redirect class (WeakMapPerStore vs GlobalObjectStore) based on the new flag.
dd-java-agent/agent-ci-visibility/src/main/java/datadog/trace/civisibility/utils/StrongMapContextStore.java Updates the store implementation to accept Function factories.
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/WeakMapPerStore.java Updates weak fallback store compute path to use Function.apply.
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/FieldBackedContextStore.java Switches non-field-injected storage between WeakMapPerStore and GlobalObjectStore under the feature flag.
Review details
  • Files reviewed: 11/11 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datadog Autotest: FAIL

This change removes KeyAwareFactory and changes the ContextStore#getOrCompute method descriptor. Existing runtime extensions that use this API can fail to load.

Open Bits AI session

🤖 Datadog Autotest · Commit ec23bdd · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@mcculls
mcculls marked this pull request as ready for review September 3, 2026 16:18
@mcculls
mcculls requested review from a team as code owners September 3, 2026 16:18
@mcculls
mcculls requested review from mhlidd and sarahchen6 and removed request for a team September 3, 2026 16:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec23bddc77

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@mcculls
mcculls force-pushed the mcculls/global-object-store-feature branch from 9369ab2 to edd9ecf Compare September 3, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core type: feature Enhancements and improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants